import { computed, reactive } from 'vue';

export default function usePagination() {
  const pagination = reactive({
    total: 100,
    current: 1,
    pageSize: 10,
    showPageSize: true,
    showTotal: true,
    showMore: true,
    showJumper: true,
  });
  const queryPagination = computed(() => {
    return {
      pageSize: pagination.pageSize,
      pageNo: pagination.current,
    };
  });

  const updateData = (key: string, value: number) => {
    Object.assign(pagination, {
      [key]: value,
    });
  };

  const setCurrent = (current: number) => {
    updateData('current', current);
  };
  const setTotal = (total: number) => {
    updateData('total', total);
  };
  const setPageSize = (pageSize: number) => {
    updateData('current', 1);
    updateData('pageSize', pageSize);
  };
  return {
    pagination,
    queryPagination,
    setCurrent,
    setTotal,
    setPageSize,
  };
}
